package cn.edu.hpu.action;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.hpu.pojo.Group;
import cn.edu.hpu.pojo.Worker;
import cn.edu.hpu.service.GroupService;
import cn.edu.hpu.service.WorkerService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class WorkerAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Worker worker;
	private WorkerService workerService;
	private Map<String, Object> session  ;
	private List<Worker> wlist;
	private List<Group> glist;
	private GroupService groupService;
	private String gid;
	private String id;
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	public String login(){
		Worker w = workerService.findA(worker);
		if (w != null) {
			session = ActionContext.getContext().getSession();
			session.put("worker", w);
			return SUCCESS;
		} else {
			return ERROR;
		}
	}
	public String leave(){
		session =  ActionContext.getContext().getSession();
		session.remove("worker");
		return SUCCESS;
	}
	public String workermessage(){
		wlist = workerService.findAllByWjob("w");
		return SUCCESS;
	}
	public String newworker(){
		glist = groupService.findAll();
		return SUCCESS;
	}
	public String saveworker(){
		Group group = groupService.findA(gid);
		workerService.save(worker,group);
		return SUCCESS;
	}
	public String workerupdate(){
		worker = workerService.findAById(id);
		glist = groupService.findAll();
		return SUCCESS;
	}
	public String updateworker(){
		Group group = groupService.findA(gid);
		workerService.update(worker,group);
		return SUCCESS;
	}
	public String workerdelete(){
		workerService.delete(id);
		return SUCCESS;
	}
	
	
	
	
	
	
	
	
	//setter,getter
	public Worker getWorker() {
		return worker;
	}
	public void setWorker(Worker worker) {
		this.worker = worker;
	}
	public WorkerService getWorkerService() {
		return workerService;
	}
	@Autowired
	public void setWorkerService(WorkerService workerService) {
		this.workerService = workerService;
	}
	public Map<String, Object> getSession() {
		return session;
	}
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public List<Worker> getWlist() {
		return wlist;
	}
	public void setWlist(List<Worker> wlist) {
		this.wlist = wlist;
	}
	public List<Group> getGlist() {
		return glist;
	}
	public void setGlist(List<Group> glist) {
		this.glist = glist;
	}
	public GroupService getGroupService() {
		return groupService;
	}
	@Autowired
	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}
	public String getGid() {
		return gid;
	}
	public void setGid(String gid) {
		this.gid = gid;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
}
